

import 'package:flutter/material.dart';

import '../../models/menu_item_model.dart';
import '../../values/app_value.dart';
import '../../values/style_value.dart';
import '../../widgets/menu_item_widget/menu_item_widget.dart';

class HomePage extends StatefulWidget {

  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();

}

class _HomePageState extends State<HomePage> {

  final List<MenuItemModel> menuItems = const [
    MenuItemModel(
      title: "内网文件分享",
      icon: Icons.ios_share_outlined,
      color: Colors.indigo,
      route: "/help",
    ),
  ];


  void _onFunctionTap(BuildContext context, MenuItemModel item) {
    // 这里可以添加路由跳转逻辑
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(content: Text("点击了：${item.title}")),
    );
    // 实际项目中使用路由跳转
    // Navigator.pushNamed(context, item.route);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: StyleValue.getAppBar(AppValue.appName),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: GridView.count(
          crossAxisCount: MediaQuery.of(context).size.width > 600 ? 4 : 2,
          crossAxisSpacing: 10,
          mainAxisSpacing: 10,
          childAspectRatio: 1.0,
          children: menuItems.map((item) {
            return MenuItemWidget(
              item: item,
              onTap: () => _onFunctionTap(context, item),
            );
          }).toList(),
        ),
      ),
    );
  }

}